var path = require('path');
var HtmlWebpackPLugin = require('html-webpack-plugin');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('[name]-one.css');
var extractLESS = new ExtractTextPlugin('[name]-two.css');
module.exports = {
  entry:{
    index:"./src/index.js",
  },
  output:{
    filename:"[name].[hash].bundle.js",
    path:path.resolve(__dirname,"static"),
    publicPath:'/static/'  //  important!!!!!这是html里面的各种资源加载路径的开头
  },
  
  devtool : '#source-map',
  module:{ 
    rules:[
      {test:/\.css$/,use: extractCSS.extract([ 'css-loader'])},
      {test:/\.less$/,use: extractCSS.extract([ 'css-loader', 'less-loader?sourceMap' ])},
      {test:/\.scss$/,use: extractCSS.extract([ 'css-loader', 'sass-loader?sourceMap' ])},
      {test:/\.js$/,use: {
        loader: 'babel-loader',
        options: {
          presets: ['es2015'],
          plugins: [require('babel-plugin-transform-object-rest-spread')]
        }
      },exclude:'/home/zsk/gitarea/mini-frontend/node_modules'},
      {test:/\.(jpg|png|gif|svg)$/,use:['file-loader']},
      {test:/\.(woff|woff2|eot|ttf|otf)/, use:['file-loader']},
      {test:/\.ejs$/, use:['ejs-loader']},
      {test:/\.html$/, use:['html-withimg-loader']}
    ]
  },

  plugins:[
    new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: '"production"'
        }
    }),
    //压缩代码
    // new webpack.optimize.UglifyJsPlugin({                                                         // 压缩文件
    //     compress: {
    //         warnings: false
    //     }
    // }),
    extractCSS,
    extractLESS,
    new webpack.optimize.CommonsChunkPlugin({name:'common',filename:'common.js'}),//针对所有的入口
    new HtmlWebpackPLugin({filename:'../templates/index.html',template:'src/template/index.html',hash:false}),//游戏选择页面
    new webpack.HotModuleReplacementPlugin() //热模块替换
  ],
  devServer:{
    // colors:true,
    port:8080,
    inline:true,
    contentBase:'dist',
    compress:true,
    hot:true
  }
}